<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
  <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
  <!-- ========================= -->
  <!-- root element: eindbazen -->
  <!-- @params studentid REQUIRED!-->
  <!-- ========================= -->
  <xsl:param name="studentid"/>
  <xsl:template match="/eindbazen">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
          <fo:region-body/>
          <fo:region-end/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="simpleA4">
        <fo:flow flow-name="xsl-region-body">
          <fo:block text-align="right">
            <fo:external-graphic src="windesheim.jpg"/>
          </fo:block>
          <fo:block font-size="20pt" font-weight="bold" space-after="8mm">
            Voortgangsrapportage
          </fo:block>
          <fo:block font-size="12pt" space-after="0mm">
            Naam: <xsl:value-of select="//studenten/child::student[@id=$studentid]/@naam"/>
          </fo:block>
          <fo:block font-size="12pt" space-after="5mm">
            Klas: <xsl:value-of select="//klassen/klas[child::student[@id=$studentid]]/@naam"/>
          </fo:block>
          <fo:block font-size="8pt">
            <fo:table table-layout="fixed" width="100%" space-after="8mm" font-size="8pt" border-color="black" border-width="0.4mm" border-style="solid">
              <fo:table-column column-width="4cm"/>
              <fo:table-column column-width="4cm"/>
              <fo:table-column column-width="4cm"/>
              <fo:table-column column-width="4cm"/>
              <fo:table-header>
                <fo:table-row font-weight="bold">
                  <fo:table-cell>
                    <fo:block>
                      <xsl:text>Naam</xsl:text>
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell>
                    <fo:block>
                      <xsl:text>Adres</xsl:text>
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell>
                    <fo:block>
                      <xsl:text>Woonplaats</xsl:text>
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell>
                    <fo:block>
                      <xsl:text>Telefoonnummer</xsl:text>
                    </fo:block>
                  </fo:table-cell>
                </fo:table-row>
              </fo:table-header>
              <fo:table-body>
                <fo:table-cell>
                  <fo:block>
                    <xsl:value-of select="//studenten/child::student[@id=$studentid]/@naam"/>
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>
                    <xsl:value-of select="//studenten/child::student[@id=$studentid]/@adres"/>
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>
                    <xsl:value-of select="//studenten/child::student[@id=$studentid]/@woonplaats"/>
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block>
                    <xsl:value-of select="//studenten/child::student[@id=$studentid]/@telefoonnr"/>
                  </fo:block>
                </fo:table-cell>
              </fo:table-body>
            </fo:table>
          </fo:block>
          <fo:block font-size="8pt">
            <!-- Check if student has cursussen -->
            <xsl:choose>
              <xsl:when test="count(//student[@id=$studentid]/cursus) &gt; 0">
                <fo:table table-layout="fixed" width="100%" space-after="10mm" font-size="8pt" border-color="black" border-width="0.4mm" border-style="solid">
                  <fo:table-column column-width="4cm"/>
                  <fo:table-column column-width="4cm"/>
                  <fo:table-column column-width="4cm"/>
                  <fo:table-column column-width="4cm"/>
                  <fo:table-header>
                    <fo:table-row font-weight="bold">
                      <fo:table-cell>
                        <fo:block>
                          Cursus naam
                        </fo:block>
                      </fo:table-cell>
                      <fo:table-cell>
                        <fo:block>
                          Omschrijving
                        </fo:block>
                      </fo:table-cell>
                      <fo:table-cell>
                        <fo:block text-align="center">
                          Toetstype
                        </fo:block>
                      </fo:table-cell>
                      <fo:table-cell>
                        <fo:block text-align="center">
                          Cijfer
                        </fo:block>
                      </fo:table-cell>
                    </fo:table-row>
                  </fo:table-header>
                  <fo:table-body>
                    <xsl:apply-templates/>
                  </fo:table-body>
                </fo:table>
              </xsl:when>
              <!-- Else -->
              <xsl:otherwise>
                <fo:block>
                  Er zijn voor deze student geen cijfers ingevoerd.
                </fo:block>
              </xsl:otherwise>
            </xsl:choose>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>

  <xsl:template match="student[@id=$studentid]/cursus">
    <fo:table-row>
      <xsl:variable name="identity" select="@id"/>
      <fo:table-cell>
        <fo:block>
          <xsl:value-of select="//cursussen/cursus[@id=$identity]/@name"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block>
          <xsl:value-of select="//cursussen/cursus[@id=$identity]/."/>
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
    <xsl:apply-templates/>
  </xsl:template>
  
  <xsl:template match="student[@id=$studentid]/cursus/cijfer">
    <fo:table-row>
      <fo:table-cell number-columns-spanned="2">
        <fo:block>&#160;</fo:block>
      </fo:table-cell>
    <fo:table-cell>
      <fo:block text-align="center">
        <xsl:value-of select="@toetstype"/>
      </fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block text-align="center">
        <xsl:value-of select="."/>
      </fo:block>
    </fo:table-cell>
    </fo:table-row>
  </xsl:template>
</xsl:stylesheet>